package com.gxa.zhonglong.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * @ClassName ResponseUtil
 * @Description TODO
 * @Author: ws
 * @date 2021/9/13 15:44
 * @Version 1.0
 */
public class ResponseUtil {

    //给前端发送json字符串
    public static void write(HttpServletResponse response, Map<String,Object> map) throws IOException {
        //将字符集设为utf-8
        response.setCharacterEncoding("UTF-8");
        response.setHeader("content-type", "text/html;charset=utf-8");

        PrintWriter writer = response.getWriter();
        writer.write(JSON.toJSONString(map));
        writer.flush();
        writer.close();
    }

}
